package org.newcih.activiti;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

/**
 * Created by 15733 on 2017/7/14.
 */
public class PrintMethod {

    private static List<Method> printMethod(Object object) {
        Class clazz = object.getClass();
        return Arrays.asList(clazz.getMethods());
    }

    public static void printMethodWithBoolean(Object object) {
        printMethod(object).forEach(method -> {
            if (method.getReturnType().equals(Boolean.class) && method.getParameterCount() == 0) {
                try {
                    System.out.println(method.getName() + " >> " + method.invoke(object));
                } catch (IllegalAccessException | InvocationTargetException e) {
                    // TODO
                }
            }
        });
    }

    public static void printMethodWithString(Object object) {
        printMethod(object).forEach(method -> {
            if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) {
                try {
                    System.out.println(method.getName() + " >> " + method.invoke(object));
                } catch (IllegalAccessException | InvocationTargetException e) {
                    // TODO
                }
            }
        });
    }

    public static void printMethodAll(Object object) {
        printMethod(object).forEach(method -> {
            if (method.getReturnType() != null && method.getParameterCount() == 0) {
                try {
                    System.out.println(method.getName() + " >> " + method.invoke(object));
                } catch (Exception e) {
                    // TODO
                }
            }
        });
    }
}
